<template></template>

<script setup>
import { tokenExpired } from "@/utils/dialog.js";
import { singleLogin } from "@/api/index.js";
import useParameter from "@/store/parameter.js";
import { onMounted } from "vue";
import { useRoute, useRouter } from "vue-router";
const route = useRoute();
const router = useRouter();
//  获取登录字符串， 如果获取成功 获取 并设置token，否则则登录失败
const { parameter } = route.query;
const token = localStorage.getItem("token");

const [new_parameter, setParameter] = useParameter();
// 记录参数，供跳转使用
setParameter(parameter || "");

//  授权登录
if (!token && parameter) {
  singleLogin(parameter)
    .then((res) => {
      const { token } = res;
      if (token) {
        localStorage.setItem("token", res?.token || null);
        router.push("/home");
      } else {
        tokenExpired();
      }
    })
    .catch((err) => {
      tokenExpired();
      console.log("获取登录参数失败", err);
    });
} else {
  router.push("/home");
}
</script>


<style scoped>
</style>